conda install Pillow
Retrieving notices: ...working... done
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done
## Package Plan ##
environment location: C:\Users\22077\anaconda3
added / updated specs:
- pillow
The following packages will be downloaded:
package | build
---------------------------|-----------------
openssl-1.1.1v | h2bbff1b_0 5.5 MB
------------------------------------------------------------
Total: 5.5 MB
The following packages will be UPDATED:
openssl 1.1.1u-h2bbff1b_0 --> 1.1.1v-h2bbff1b_0
Downloading and Extracting Packages
openssl-1.1.1v | 5.5 MB | | 0%
openssl-1.1.1v | 5.5 MB | | 0%
openssl-1.1.1v | 5.5 MB | | 1%
openssl-1.1.1v | 5.5 MB | | 1%
openssl-1.1.1v | 5.5 MB | 1 | 2%
openssl-1.1.1v | 5.5 MB | 2 | 2%
openssl-1.1.1v | 5.5 MB | 3 | 3%
openssl-1.1.1v | 5.5 MB | 3 | 4%
openssl-1.1.1v | 5.5 MB | 4 | 4%
openssl-1.1.1v | 5.5 MB | 5 | 5%
openssl-1.1.1v | 5.5 MB | 6 | 7%
openssl-1.1.1v | 5.5 MB | 7 | 7%
openssl-1.1.1v | 5.5 MB | 8 | 9%
openssl-1.1.1v | 5.5 MB | 9 | 9%
openssl-1.1.1v | 5.5 MB | #1 | 11%
openssl-1.1.1v | 5.5 MB | #2 | 12%
openssl-1.1.1v | 5.5 MB | #3 | 13%
openssl-1.1.1v | 5.5 MB | #5 | 16%
openssl-1.1.1v | 5.5 MB | #6 | 16%
openssl-1.1.1v | 5.5 MB | #7 | 17%
openssl-1.1.1v | 5.5 MB | #9 | 20%
openssl-1.1.1v | 5.5 MB | ## | 21%
openssl-1.1.1v | 5.5 MB | ##2 | 22%
openssl-1.1.1v | 5.5 MB | ##4 | 25%
openssl-1.1.1v | 5.5 MB | ##5 | 26%
openssl-1.1.1v | 5.5 MB | ##6 | 27%
openssl-1.1.1v | 5.5 MB | ##8 | 28%
openssl-1.1.1v | 5.5 MB | ##9 | 29%
openssl-1.1.1v | 5.5 MB | ### | 30%
openssl-1.1.1v | 5.5 MB | ###1 | 32%
openssl-1.1.1v | 5.5 MB | ###4 | 34%
openssl-1.1.1v | 5.5 MB | ###5 | 35%
openssl-1.1.1v | 5.5 MB | ###6 | 37%
openssl-1.1.1v | 5.5 MB | ###7 | 38%
openssl-1.1.1v | 5.5 MB | ###8 | 39%
openssl-1.1.1v | 5.5 MB | #### | 41%
openssl-1.1.1v | 5.5 MB | ####1 | 42%
openssl-1.1.1v | 5.5 MB | ####2 | 43%
openssl-1.1.1v | 5.5 MB | ####4 | 44%
openssl-1.1.1v | 5.5 MB | ####5 | 46%
openssl-1.1.1v | 5.5 MB | ####7 | 47%
openssl-1.1.1v | 5.5 MB | ####9 | 49%
openssl-1.1.1v | 5.5 MB | ##### | 51%
openssl-1.1.1v | 5.5 MB | #####2 | 52%
openssl-1.1.1v | 5.5 MB | #####3 | 54%
openssl-1.1.1v | 5.5 MB | #####5 | 55%
openssl-1.1.1v | 5.5 MB | #####6 | 57%
openssl-1.1.1v | 5.5 MB | #####8 | 58%
openssl-1.1.1v | 5.5 MB | ###### | 60%
openssl-1.1.1v | 5.5 MB | ######1 | 62%
openssl-1.1.1v | 5.5 MB | ######2 | 63%
openssl-1.1.1v | 5.5 MB | ######4 | 65%
openssl-1.1.1v | 5.5 MB | ######6 | 66%
openssl-1.1.1v | 5.5 MB | ######8 | 69%
openssl-1.1.1v | 5.5 MB | ####### | 70%
openssl-1.1.1v | 5.5 MB | #######2 | 72%
openssl-1.1.1v | 5.5 MB | #######4 | 74%
openssl-1.1.1v | 5.5 MB | #######6 | 76%
openssl-1.1.1v | 5.5 MB | #######7 | 78%
openssl-1.1.1v | 5.5 MB | #######9 | 79%
openssl-1.1.1v | 5.5 MB | ########1 | 81%
openssl-1.1.1v | 5.5 MB | ########3 | 83%
openssl-1.1.1v | 5.5 MB | ########5 | 85%
openssl-1.1.1v | 5.5 MB | ########6 | 87%
openssl-1.1.1v | 5.5 MB | ########8 | 89%
openssl-1.1.1v | 5.5 MB | ######### | 90%
openssl-1.1.1v | 5.5 MB | #########2 | 92%
openssl-1.1.1v | 5.5 MB | #########3 | 94%
openssl-1.1.1v | 5.5 MB | #########6 | 96%
openssl-1.1.1v | 5.5 MB | #########8 | 99%
openssl-1.1.1v | 5.5 MB | ########## | 100%
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
Note: you may need to restart the kernel to use updated packages.
==> WARNING: A newer version of conda exists. <==
current version: 23.3.1
latest version: 23.7.2
Please update conda by running
$ conda update -n base -c defaults conda
Or to minimize the number of packages updated during conda update use
conda install conda=23.7.2
Computer vision is a field of artificial intelligence that gives computers the ability to see, understand, and interpret the visual world The goal of computer vision is to enable computers to see the world in the same way that humans do. This is a challenging task, as the visual world is complex and constantly changing. However, recent advances in artificial intelligence and machine learning have made significant progress in the field of computer vision
what is an Image
a digital image is not a continuous image, like a painting or a photograph. Instead, it is made up of a grid of pixels, and each pixel has a specific value that represents its color or brightness. It is an array of pixels arranged in columns and rows. Pixels are the elements of an image that contain information about intensity and color.Pixels are arranged in the form of a matrix. This is known as an RGB image
![]()

what is Image Processing ?
Image Processing is the core part of computer vision. It plays a crucial role in many real-world examples like robotics, self-driving cars, and object detection. Image processing allows us to transform and manipulate thousands of images at a time and extract useful insights from them. It has a wide range of applications in almost every field.
Why Python ?
Python is one of the widely used programming languages for this purpose. Its amazing libraries and tools help in achieving the task of image processing very efficiently.
what we are going to be exploring today ?
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
# Import images
pic = plt.imread(r"C:\Users\22077\Downloads\Covenant.jpg") #to read the color pixels
pic
array([[[201, 215, 218],
[199, 213, 214],
[198, 212, 213],
...,
[134, 109, 105],
[124, 109, 102],
[129, 119, 110]],
[[199, 213, 214],
[198, 212, 213],
[198, 212, 213],
...,
[138, 113, 109],
[128, 109, 105],
[133, 115, 111]],
[[197, 211, 212],
[198, 212, 213],
[200, 214, 215],
...,
[136, 110, 109],
[132, 106, 105],
[137, 111, 110]],
...,
[[112, 135, 83],
[111, 134, 82],
[111, 134, 82],
...,
[112, 137, 79],
[122, 147, 89],
[118, 143, 85]],
[[114, 137, 85],
[110, 133, 81],
[109, 132, 80],
...,
[113, 138, 80],
[116, 141, 83],
[116, 141, 83]],
[[112, 135, 83],
[108, 131, 79],
[107, 130, 78],
...,
[105, 130, 72],
[115, 140, 82],
[106, 131, 73]]], dtype=uint8)
#importing images
#load images using numpy
pic = plt.imread(r"C:\Users\22077\Downloads\Covenant.jpg") #to read the color pixels
plt.imshow(pic)
<matplotlib.image.AxesImage at 0x264c01ce1a0>
# filtering the images with colour gradient
# RGB
# R(0) B(1) G(2)
red = pic[:,:,0]
red
array([[201, 199, 198, ..., 134, 124, 129],
[199, 198, 198, ..., 138, 128, 133],
[197, 198, 200, ..., 136, 132, 137],
...,
[112, 111, 111, ..., 112, 122, 118],
[114, 110, 109, ..., 113, 116, 116],
[112, 108, 107, ..., 105, 115, 106]], dtype=uint8)
plt.imshow(red)
<matplotlib.image.AxesImage at 0x264c028b490>
# filtering the images with colour gradient
# RGB
# R(0) B(1) G(2)
green = pic[:,:,1]
green
array([[215, 213, 212, ..., 109, 109, 119],
[213, 212, 212, ..., 113, 109, 115],
[211, 212, 214, ..., 110, 106, 111],
...,
[135, 134, 134, ..., 137, 147, 143],
[137, 133, 132, ..., 138, 141, 141],
[135, 131, 130, ..., 130, 140, 131]], dtype=uint8)
plt.imshow(green)
<matplotlib.image.AxesImage at 0x264c64ff640>
# filtering the images with colour gradient
# RGB
# R(0) B(1) G(2)
blue = pic[:,:,2]
blue
array([[218, 214, 213, ..., 105, 102, 110],
[214, 213, 213, ..., 109, 105, 111],
[212, 213, 215, ..., 109, 105, 110],
...,
[ 83, 82, 82, ..., 79, 89, 85],
[ 85, 81, 80, ..., 80, 83, 83],
[ 83, 79, 78, ..., 72, 82, 73]], dtype=uint8)
plt.imshow(blue)
<matplotlib.image.AxesImage at 0x264c6563d30>
# Creating Canvas using Numpy
cav = np.zeros((900,900))
plt.imshow(cav)
<matplotlib.image.AxesImage at 0x264c74f4430>
# loading images using pill library
pic1 = Image.open(r"C:\Users\22077\Downloads\CR7.jpeg")
#pic1 = pic1.resize((500,500))
pic1
red_pic,green_pic, blue_pic = pic1.copy(),pic1.copy(),pic1.copy()
pic1 = np.array(pic1)
pic1
array([[[107, 156, 65],
[107, 156, 65],
[107, 156, 65],
...,
[100, 149, 58],
[100, 149, 58],
[ 98, 147, 56]],
[[107, 156, 65],
[107, 156, 65],
[107, 156, 65],
...,
[100, 149, 58],
[101, 150, 59],
[ 98, 147, 56]],
[[107, 156, 65],
[107, 156, 65],
[106, 155, 64],
...,
[101, 150, 59],
[101, 150, 59],
[ 99, 148, 57]],
...,
[[130, 15, 12],
[126, 10, 10],
[131, 13, 13],
...,
[153, 19, 30],
[154, 18, 30],
[152, 14, 27]],
[[129, 16, 12],
[125, 11, 10],
[129, 13, 13],
...,
[154, 18, 30],
[155, 17, 30],
[152, 14, 27]],
[[129, 16, 12],
[125, 11, 10],
[129, 13, 13],
...,
[154, 18, 30],
[155, 17, 30],
[154, 14, 27]]], dtype=uint8)
pic1 = np.array(pic1)
red_pic[:,:,(1,2)] = 0
plt.imshow(red_pic)
<matplotlib.image.AxesImage at 0x264c1a00460>
img_red = np.array(red_pic)
plt.imshow(img_red[:,:,(1,2)] = 0) # this is showing red. meaning
Cell In[40], line 2 plt.imshow(img_red[:,:,(1,2)] = 0) # this is showing red. meaning ^ SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
# Assuming pic1 is your original image
red_pic, green_pic, blue_pic = pic1.copy(), pic1.copy(), pic1.copy()
red_pic[:, :, (1, 2)] = 0
green_pic[:, :, (0, 2)] = 0
blue_pic[:, :, (0, 1)] = 0
cmb = np.concatenate((red_pic, green_pic, blue_pic), axis=1)
plt.imshow(cmb)
plt.show()
pic1 = np.array(pic)
red_pic,green_pic,blue_pic = pic1.copy(),pic1.copy(),pic1.copy()
red_pic[:,:,(1,2)] = 0
green_pic[:,:,(0,2)] = 0
blue_pic[:,:,(0,1)]= 0
cmb = np.concatenate((red_pic,green_pic,blue_pic),axis=1)
plt.figure(figsize=(11,11))
plt.imshow(cmb)
<matplotlib.image.AxesImage at 0x264d630b2e0>
output_file = "cmb.jpg" # Replace this with your desired output file name and format
plt.savefig("cmb.jpg")
<Figure size 640x480 with 0 Axes>
red_pic,green_pic,blue_pic = pic1.copy(),pic1.copy(),pic1.copy()
red_pic[:,:,(1,2)] = 0
green_pic[:,:,(0,2)] = 0
blue_pic[:,:,(0,1)]= 0
cmb = np.concatenate((red_pic,green_pic,blue_pic),axis=1)
plt.figure(figsize=(11,11))
plt.imshow(cmb)
<matplotlib.image.AxesImage at 0x264d62cfa00>
#Gray Scale image
gray = pic[:,:,0]
plt.imshow(gray, cmap='gray')
<matplotlib.image.AxesImage at 0x264cddff6a0>
# open CV library
# it uses the BRG format rather than RBG like the Pillow or Numpy
import cv2
cv_image = cv2.imread(r"C:\Users\22077\Downloads\Covenant.jpg")
plt.imshow(cv_image) # note the blue image because the openCV library has the BRG format. Hence, more blue
<matplotlib.image.AxesImage at 0x264cdf06c80>
#to have the original colour
cv_image2 = cv2.cvtColor(cv_image,cv2.COLOR_BGR2RGB) # Note the BRG2RGB. we can also do BRG2GRAY
plt.imshow(cv_image2)
<matplotlib.image.AxesImage at 0x264cdfdc220>
cv_image2 = cv2.cvtColor(cv_image,cv2.COLOR_BGR2GRAY) # Note the BRG2RGB. we can also do BRG2GRAY
plt.imshow(cv_image2)
<matplotlib.image.AxesImage at 0x264d1c06260>
flip = cv2.flip(cv_image2, -1) #vertical flip
plt.imshow(flip)
<matplotlib.image.AxesImage at 0x264ce0949d0>
flip = cv2.flip(cv_image, 1) #vertical flip
plt.imshow(flip) #look closely to see the flip from right to left
<matplotlib.image.AxesImage at 0x264ce0f8fd0>
# Rotating images in openCV
img = Image.open(r"C:\Users\22077\Downloads\Covenant.jpg")
rot_im = img.rotate(45) # rotation
plt.figure(figsize=(10,10))
plt.imshow(rot_im)
<matplotlib.image.AxesImage at 0x264d1d7ab60>
# Creating Canvas using Numpy
# Creating Graphical images
cav1 = np.zeros((900,900,3))# the '3' will change it to
plt.imshow(cav1)
<matplotlib.image.AxesImage at 0x264d1b3e290>
# Creating Canvas using Numpy
# Creating Graphical images
cav2 = np.zeros((900,900,3))# the '3' will change it to black
plt.imshow(cav2)
<matplotlib.image.AxesImage at 0x264fb323040>
cv2.rectangle(cav2,pt1=[200,200],pt2=[800,800],color=(60,150,255),thickness=8)
plt.imshow(cav2)
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
<matplotlib.image.AxesImage at 0x264fb3b5420>
cav4 = np.ones((1000,1000,1))
plt.imshow(cav4)
<matplotlib.image.AxesImage at 0x264847ec9d0>
cv2.circle(cav4, center=(500,650),radius=20, color=(0,150,240), thickness=5)
plt.imshow(cav4)
<matplotlib.image.AxesImage at 0x2648483b490>
can5 = np.zeros((1000, 1000, 3), dtype=np.uint8)
red = can5.copy()
blue = can5.copy()
green = can5.copy()
# Set the value for the colored squares in each channel
red[200:400, 200:400, 0] = 255 # R channel (Red square)
blue[250:450, 250:450, 2] = 255 # B channel (Blue square)
green[300:500, 300:500, 1] = 255 # G channel (Green square)
# Convert the colored squares to grayscale
red = Image.fromarray(red).convert("L")
blue = Image.fromarray(blue).convert("L")
green = Image.fromarray(green).convert("L")
# Merge the grayscale images back into a single RGB image
C = Image.merge("RGB", [red, green, blue])
# Display the merged image
plt.imshow(C)
plt.show()